package com.uenpay.im.weight;

import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;

import com.uenpay.im.R;
import com.uenpay.im.callback.OnPasswordInputFinish;
import com.uenpay.im.view.PasswordView;

/**
 * @author SL
 * @copyRight http://www.qiyunxin.com
 * @E-mail:
 * @date 创建时间：2016-5-6 下午2:46:59
 * @version 1.0
 * @function 支付密码输入框
 */
public class PayPwdDialog {

	/**
	 * 支付密码输入
	 * 
	 * @param mContext
	 * @param mIPayPwdInputFinishListener
	 */
	public static void showBottomRedDialog(Context mContext, final IPayPwdInputFinishListener mIPayPwdInputFinishListener) {
		final Dialog dialog = new Dialog(mContext, R.style.pop_dialog);
		dialog.setContentView(R.layout.pay_pwd_dialog_layout);
		Window win = dialog.getWindow();
		win.setGravity(Gravity.BOTTOM);
		win.setWindowAnimations(R.style.dialogWindowAnim);
		dialog.setCanceledOnTouchOutside(true);
		dialog.show();
		win.setLayout(android.view.ViewGroup.LayoutParams.MATCH_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
		final PasswordView mPasswordView = (PasswordView) dialog.findViewById(R.id.pay_pwd_layout);
		mPasswordView.setIForgetPwdListener(new PasswordView.IForgetPwdListener() {

			@Override
			public void onForgetPwdResult() {
				dialog.dismiss();
			}
		});
		mPasswordView.setOnFinishInput(true, new OnPasswordInputFinish() {

			@Override
			public void inputFinish() {
				String payPwd = mPasswordView.getStrPassword();
				if (!TextUtils.isEmpty(payPwd)) {
					mIPayPwdInputFinishListener.onPayPwdInputFinish(payPwd);
					dialog.dismiss();
				}
			}

		});

		dialog.findViewById(R.id.close_iv).setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View arg0) {
						dialog.dismiss();
					}
				});
	}

	/**
	 * 密码输入完成回调
	 * 
	 * @author SL
	 * 
	 */
	public interface IPayPwdInputFinishListener {
		public abstract void onPayPwdInputFinish(String payPwd);
	}
}
